﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Forum.Entity.Member;
using Forum.DAL.Member;
using Forum.BLL.Group;
using System.Reflection;
using Forum.Entity.Group;
using Frame.Lib.Web;
using Frame.Lib.Core.Base;


namespace Forum.BLL.Member
{
    public class ForumMemberBO : CommonOperate<ForumMemberInfo>
    {
        private ForumMemberDAL _forumMember;
        protected override BaseDAL DAL
        {
            get
            {
                return _forumMember;

            }
        }
        public ForumMemberBO()
        {
            _forumMember = new ForumMemberDAL();
        }

        

        public override void Save(ForumMemberInfo info)
        {

            base.Save(info);
        }

        public override ForumMemberInfo GetInfo(object id)
        {
            if (id == null)
            {
                return new ForumMemberInfo();
            }
            ForumMemberInfo info = base.GetInfo(id);
            MemberBaseBO siteMember = new MemberBaseBO();
            ForumGroupBO group = new ForumGroupBO();
            siteMember.dbOper = group.dbOper = this.dbOper;
            info.GetMemberBaseInfo = memberID => siteMember.GetInfo(memberID);
            info.GetGroupInfo = memberID => group.GetInfo(memberID);
            
            return info;
        }



        public override List<ForumMemberInfo> GetList(PagerSortSetting pagerSetting, string condition, params object[] conditionParas)
        {
            List<ForumMemberInfo> list = _forumMember.GetList(pagerSetting, condition, conditionParas);

            ForumGroupBO group = new ForumGroupBO();
            List<ForumGroupInfo> groupList = group.GetList();

            foreach (ForumMemberInfo info in list)
            {
                info.GroupName = groupList.Where(T => T.ID == info.GroupID).Select(T => T.Name).First();
            }
            return list;
        }
    }
}
